﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace tp
{
    public partial class tianxie : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Usernew"] != null)
            {
                string str;
                str = (string)Session["Usernew"];
                this.txtname.Text = Session["Usernew"].ToString();
            }
            
        }

        protected void ddlpro_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlpro.SelectedValue == "广东省")
            {
                ddlcity.Items.Clear();
                ddlcity.Items.Add("汕头市");
                ddlcity.Items.Add("梅州市");
            }
            else if (ddlpro.SelectedValue == "广西省")
            {
                ddlcity.Items.Clear();
                ddlcity.Items.Add("桂林市");
                ddlcity.Items.Add("柳州市");
            }
            else
            {
                ddlcity.Items.Clear();
            }
        }

        protected void ddlcity_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlcity.SelectedValue == "汕头市")
            {
                ddlcown.Items.Clear();
                ddlcown.Items.Add("潮阳区");
                ddlcown.Items.Add("潮南区");
            }
            else if (ddlcity.SelectedValue == "梅州市")
            {
                ddlcown.Items.Clear();
                ddlcown.Items.Add("梅江区");
                ddlcown.Items.Add("梅县区");
            }
            else if (ddlcity.SelectedValue == "桂林市")
            {
                ddlcown.Items.Clear();
                ddlcown.Items.Add("象山区");
                ddlcown.Items.Add("秀峰区");
            }
            else if (ddlcity.SelectedValue == "柳州市")
            {
                ddlcown.Items.Clear();
                ddlcown.Items.Add("柳南区");
                ddlcown.Items.Add("鱼峰区");
            }
            else
            {
                ddlcown.Items.Clear();
            }
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Request.QueryString["Theme"] != null)
                Page.Theme = Request.QueryString["Theme"].ToString();

        }
        protected void ibhuanfu_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("tianxie.aspx?Theme=" + ddlhuanfu.SelectedValue + "");
        }

        protected void ddlhuanfu_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void ibsure_Click(object sender, ImageClickEventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112142;uid=2014112142;pwd=19961124";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                StringBuilder sb = new StringBuilder(1024);
                sb.Append("INSERT INTO Infomation ");
                sb.Append("(No, Name, College, Birth,Iden,Addr,Age) ");
                sb.Append("VALUES   (@No,@Name,@College,@Birth,@Iden,@Addr,@Age) ");

                SqlCommand cmd = new SqlCommand(sb.ToString(), cn);
                SqlParameter pmsNo = new SqlParameter("@No", this.txtno.Text);
                SqlParameter pmsName = new SqlParameter("@Name", this.txtname.Text);
                SqlParameter pmsCollege = new SqlParameter("@College", this.ddlcoll.Text);
                SqlParameter pmsBirth = new SqlParameter("@Birth", this.ddlyear.Text + this.ddlmonth.Text + this.ddlday.Text);
                SqlParameter pmsIden = new SqlParameter("@Iden", this.txtiden.Text);
                SqlParameter pmsAddr = new SqlParameter("@Addr", this.ddlpro.Text + this.ddlcity.Text + this.ddlcown.Text);
                SqlParameter pmsAge = new SqlParameter("@Age", this.ddlage.Text);
                cmd.Parameters.Add(pmsNo);
                cmd.Parameters.Add(pmsName);
                cmd.Parameters.Add(pmsCollege);
                cmd.Parameters.Add(pmsBirth);
                cmd.Parameters.Add(pmsIden);
                cmd.Parameters.Add(pmsAddr);
                cmd.Parameters.Add(pmsAge);
                int iInsert = cmd.ExecuteNonQuery();
                if (iInsert < 1)
                {
                    lbl.Text = "添加信息失败！";
                }
                else
                {
                    Response.Write("<script>alert('请再次登录！'); location.href = '/index.aspx';</script>");
                }
            }
            catch (Exception ex)
            {
                this.lbl.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }
    }
}